// i.d(t, { o: () => RenderLayers })
export class RenderLayer {
  _mask: number
  constructor(e: number) {
    this._mask = e
  }
  get mask() {
    return this._mask
  }
  addLayers(e: RenderLayer) {
    this._mask |= e.mask
  }
  removeLayers(e: RenderLayer) {
    return (this._mask &= ~e.mask)
  }
  clone() {
    return new RenderLayer(this._mask)
  }
}
export default class RenderLayers {
  layerRegistry: string[]
  unusedLayers: number[]
  constructor() {
    this.layerRegistry = []
    this.unusedLayers = []
    for (let e = 1; e < 32; e++) this.unusedLayers.push(e)
  }
  static get ALL() {
    return new RenderLayer(-1)
  }
  static get NONE() {
    return new RenderLayer(0)
  }
  static get DEFAULT() {
    return new RenderLayer(1)
  }
  claimLayer(e: string) {
    const t = this.getLayer(e)
    if (t.mask) return t
    if (0 === this.unusedLayers.length) throw Error("All render layers have already been claimed")
    const i = this.unusedLayers[0]
    this.layerRegistry[i] = e
    this.unusedLayers.shift()
    return new RenderLayer(1 << i)
  }
  getLayer(e: string) {
    const t = this.layerRegistry.indexOf(e)
    return -1 !== t ? new RenderLayer(1 << t) : RenderLayers.NONE
  }
  disposeLayer(e: string) {
    const t = this.layerRegistry.indexOf(e)
    t !== -1 && this.unusedLayers.push(t)
  }
}
